import sys
import configs
from input_stream import Speech_recognition
from dependments import *
from write_stream import Class_control_messages
from speech_parsing import Tags_decoder, Tags_wrapper, Wrapper_decoders, Tags_key
from core_apps import Settings_Core, Apps


class Core:
    def __init__(self) -> None:
        self.obj_control_mess = Class_control_messages()
        obj_apps = Apps()
        obj_work_mode = Work_mode()
        obj_settings = Settings_Core()
        obj_apps.set_control_mess(self.obj_control_mess)
        obj_settings.set_control_mess(self.obj_control_mess)
        obj_tags_wrap = Tags_wrapper()
        obj_tags_wrap.set_control_mess(self.obj_control_mess)
        # self.obj_work_mode = Work_mode()
        obj_wrapper_decoders = Wrapper_decoders()
        obj_wrapper_decoders.set_work_mode(obj_work_mode)
        self.obj_calls_wrapper = Wrapper_calls_func()
        self.obj_calls_wrapper.set_wrap_decoder_mess(
            self.obj_control_mess, obj_wrapper_decoders
        )

        # print(Tags_wrapper().__class__.__name__)
        self.obj_calls_wrapper.set_tags_decoder(obj_tags_wrap, Tags_key())
        self.obj_calls_wrapper.set_work_mode(obj_work_mode)
        self.obj_calls_wrapper.set_apps(obj_apps, obj_settings)
        self.obj_calls_wrapper.set_import_core_app(Import_core_apps())
        self.obj_calls_wrapper.set_import_egg(Import_egg())
        self.obj_calls_wrapper.init_calls_events()
        obj_speech_recognition = Speech_recognition()
        obj_speech_recognition.start_recognition()

    def main(self) -> None:
        # self.obj_work_mode.update_timer_name()
        while not configs.exit_flag:
            # try:
            self.obj_calls_wrapper.Main_call_func()
            # obj_config.service_functions_obj.dec_queue_clear()
            # obj_config.communication_obj.event_message()
            # except Exception as e:
            # obj_config.communication_obj.messege(f"Фатальная ошибка {e}")
            # config.exit_flag=True
        exit(1)


# if __name__ == "main":
obj = Core()
obj.main()
